package com.shaoshaohuo.app.adapter;

import java.util.List;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.Coupon;
import com.shaoshaohuo.app.utils.StringHelper;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class ConponListAdapter<T> extends MyBaseAdapter<Coupon> {

	public ConponListAdapter(Context ctx, List<Coupon> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		
		ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context,R.layout.view_conpon_list_item, null);
            holder = new ViewHolder();
            holder.titleText = (TextView) convertView.findViewById(R.id.textview_title);
            holder.timeText = (TextView) convertView.findViewById(R.id.textview_time);
            holder.contentText = (TextView) convertView.findViewById(R.id.textview_money);
            holder.mStateImage = (ImageView) convertView.findViewById(R.id.imageview_status_image);
            holder.contentLayout =  convertView.findViewById(R.id.layout_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
		
        Coupon msg = list.get(pos);
        
        holder.titleText.setText(msg.getTitle());
        holder.timeText.setText("有效期至:"+StringHelper.formatDateDay(msg.getEndtime()));
        holder.contentText.setText("￥"+msg.getTotal());
        if("4".equals(msg.getStatus())){
        	holder.contentLayout.setBackgroundResource(R.drawable.bg_conpon_used);
        	holder.mStateImage.setVisibility(View.VISIBLE);
        }else{
        	holder.contentLayout.setBackgroundResource(R.drawable.bg_conpon_un_used);
        	holder.mStateImage.setVisibility(View.GONE);
        }
        
        
		return convertView;
	}
	
	static class ViewHolder{
		TextView titleText;
		TextView timeText;
		TextView contentText;
		ImageView mStateImage;
		View contentLayout;
	}
	
}
